package com.googlecode.c4e.ui.views.internal;

import org.eclipse.jface.action.Action;

import com.googlecode.c4e.ui.ContinuumPlugin;
import com.googlecode.c4e.ui.internal.preferences.IPreferenceIds;
import com.googlecode.c4e.ui.views.ServersView;

public class ViewLayoutChangeAction extends Action {

	private String layout;
	private ServersView view;

	public ViewLayoutChangeAction(ServersView view, String layout) {
		this.layout = layout;
		this.view = view;
		String currentLayout = ContinuumPlugin.getDefault()
				.getPreferenceStore().getString(
						IPreferenceIds.SERVERS_VIEW_PRESENTATION);
		if (currentLayout == null) {
			currentLayout = ServersView.TREE;
		}
		setChecked(currentLayout.equals(layout));
		setText(layout);
	}

	public int getStyle() {
		return AS_RADIO_BUTTON;
	}

	public void run() {
		ContinuumPlugin.getDefault().getPreferenceStore().setValue(
				IPreferenceIds.SERVERS_VIEW_PRESENTATION, layout);
		view.refreshViewer();
	}

}
